<template>
  <div><el-table
    :data="tableData"
    border
    :cell-style='cellStyle'
    :header-cell-style='rowClass'
    style="width: 100%"
    :row-class-name="tableRowClassName">
    <el-table-column
      prop="activityId"
      v-if=false>
    </el-table-column>
    <el-table-column
      prop="full"
      label="满"
      width="">
    </el-table-column>
    <el-table-column
      prop="decrease"
      label="减"
      width="">
    </el-table-column>
    <el-table-column
      label="操作"
      width="">
      <template slot-scope="scope">
        <el-button
          @click.native.prevent="resetRow(scope.$index,scope.row)"
          type="text"
          size="40">
          修改
        </el-button>
        <el-button
          @click.native.prevent="deleteRow(scope.$index,scope.row)"
          type="text"
          size="40">
          删除
        </el-button>
      </template>
    </el-table-column>
  </el-table>
    <el-dialog
      title="温馨提示"
      :visible.sync="dialogVisible"
      width="30%">
      <span>您确定要删除吗</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="isDelete">确 定</el-button>
        <el-button type="primary" @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog></div>

</template>

<style>
</style>

<script>
  import {requestGet, requestPost} from "../../../../network/request";

  export default {
    name: 'userList',
    methods: {
       cellStyle({row, column, rowIndex, columnIndex}){
         return 'text-align:center';
         },
      rowClass({row, rowIndex}){
         return 'text-align:center';
          },
      isDelete(){
         this.dialogVisible = false;
         //删除
        requestPost({
          url: 'activity/delete',
          data: {
            activityId: this.id
          }
        });
        this.tableData.splice(this.index, 1);
      },
      deleteRow(index,row) {
        this.index = index;
        this.id = row.activityId;
        this.dialogVisible = true
      },
      resetRow(index,row){
        let id = row.activityId;
        this.$router.push('/content/resetUser/'+id)
      },
      tableRowClassName({row, rowIndex}) {
        if (rowIndex === 1) {
          return 'warning-row';
        } else if (rowIndex === 3) {
          return 'success-row';
        }
        return '';
      }
    },
    mounted() {
      requestGet({
        url: 'activity/all'
      }).then(response=>{
        console.log(response.data);
        this.tableData = response.data.list
      })
    },
    data() {
      return {
        index: null,
        id: null,
        dialogVisible: false,
        tableData: [
          // {
          //   activityId:2,
          //   full:60,
          //   decrease:10
          // }
        ]
      }
    }
  }
</script>
